//-------------------------------------------------------------------------------------
// <copyright file="Create.cs" company="Microsoft">
//      Copyright (c) 2003 Microsoft Corporation. All rights reserved.
//      THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
//      EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
//      WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// </copyright>
// <summary>
//      Checks whether a Receive Port exists in a BizTalk installation.
// </summary>  
//-------------------------------------------------------------------------------------

namespace Microsoft.Sdc.Tasks.BizTalk2004.ReceivePort
{
    #region Using directives

    using System;

    using Microsoft.Build.Framework;
    using Microsoft.Sdc.Tasks.BizTalk2004.Configuration;
    using Microsoft.Sdc.Tasks;

    #endregion


    #region Class Comments
    /// <summary>
    /// Checks whether a Receive Port exists in a BizTalk installation.
    /// </summary>
    /// <remarks>
    /// <code>
    /// <![CDATA[<BizTalk2004.ReceivePort.Exists Name="name" Server="server" Database="database" />]]>
    /// </code>
    /// <para>where:</para>
    /// <para><i>Name (Required)</i></para>
    /// <para>
    /// The name of the receive port to check for.
    /// </para>
    /// <para><i>server</i></para>
    /// <para>
    /// The logical name of the server hosting the BizTalk management database. If neither this nor the
    /// database name are specified then the installation will default to the local installation.
    /// </para>
    /// <para><i>database</i></para>
    /// <para>
    /// The name of the BizTalk management database. If neither this nor the server name are specified 
    /// then the installation will default to the local installation.
    /// </para>
    /// <para><i>username</i></para>
    /// <para>
    /// The username to use to connect to the database if using SQL Server security. The default is to
    /// connect using Windows Integrated security.
    /// </para>
    /// <para><i>password</i></para>
    /// <para>
    /// The password to use to connect to the database if using SQL Server security. The default is to
    /// connect using Windows Integrated security.
    /// </para>
    /// </remarks>
    /// <example>
    /// <code><![CDATA[
    /// <Project>
    ///     <Target Name="Test" >
    ///            <BizTalk2004.ReceivePort.Exists 
    ///                Name="ReceivePort 1">
    ///                <Output TaskParameter="ReceivePortExists" PropertyName="BTSReceivePortExists" />
    ///            </BizTalk2004.ReceivePort.Exists>
    /// 
    ///      </Target>
    /// </Project>
    /// ]]></code>    
    /// </example>
    #endregion
    public class Exists : BizTalk2004TaskBase
    {
        #region Member variables 

        private string name;
        private bool exists;
        
        #endregion 

        #region Properties 
        /// <summary>
        /// The name of the receive port.
        /// </summary>
        /// <value>The name of the receive port.</value>
        [Required]
        public string Name
        {
            get { return this.name; }
            set { this.name = value; }
        }

        /// <summary>
        /// Gets whether the receive port does exist in the installation
        /// </summary>
        /// <value><b>true</b> if the recive port is exists <b>false</b> otherwise.</value>
        [Output]
        public bool ReceivePortExists
        {
            get { return this.exists; }
            protected set { this.exists = value; }
        }

        #endregion 


        #region Methods 

        /// <summary>
        /// Initializes a new instance of the Exists class.
        /// </summary>
        public Exists()
        {

        }

        /// <summary>
        /// Performs the action for this task
        /// </summary>
        protected override void InternalExecute()
        {
            //getting the installation and creating the new receive port.
            Microsoft.Sdc.Tasks.BizTalk2004.Configuration.BizTalkInstallation installation = this.GetInstallation();

            this.exists = Microsoft.Sdc.Tasks.BizTalk2004.Configuration.ReceivePort.Exists(installation, this.name);

        }

        #endregion 
    }
}

